
function search(){
    $("#page").val("1");
    $("#search_form").submit();
};
function toIsEmpty(){
	document.getElementsByName("promotionNo")[0].value = "";
	document.getElementsByName("title")[0].value = "";
	document.getElementsByName("status")[0].value = "";
	document.getElementsByName("type")[0].value = "";
	document.getElementsByName("position")[0].value = "";
    $("#page").val("1");
 };
 function downPromotion(id){
	 layer.confirm("确定下线？",function(){
			layer.closeAll('dialog');
			var layer_load_window = layer.load(2); 
			 $.ajax({
					url : path+"/promotion/down_promotion",
					cache : false,
					type : 'post',
					dataType : 'text',
					data:{'promotionId':id},
					error : function() {
						layer.alert("操作失败！");
			       },
					success : function(data) {
						var resultArr = data.split(",");
				   		if(resultArr[0] == "success"){
							layer.msg("下线成功!",{icon:1,time:1000},function(){
						    	$("#search_form").submit();
							});
				   		}else if(resultArr[0] == "fail"){
				   			layer.alert(resultArr[1]);
				   		}else{
				   			layer.alert(data);
				   		}
					},
					complete: function(XMLHttpRequest, textStatus) {
						layer.close(layer_load_window);
					}
				  })	
		 });
 }
 function upPromotion(id){
	 layer.confirm("确定上线？",function(){
			layer.closeAll('dialog');
			var layer_load_window = layer.load(2); 
			 $.ajax({
					url : path+"/promotion/up_promotion",
					cache : false,
					type : 'post',
					dataType : 'text',
					data:{'promotionId':id},
					error : function() {
						layer.alert("操作失败！");
			       },
					success : function(data) {
						var resultArr = data.split(",");
				   		if(resultArr[0] == "success"){
							layer.msg("上线成功!",{icon:1,time:1000},function(){
						    	$("#search_form").submit();
							});
				   		}else if(resultArr[0] == "fail"){
				   			layer.alert(resultArr[1]);
				   		}else{
				   			layer.alert(data);
				   		}
					},
					complete: function(XMLHttpRequest, textStatus) {
						layer.close(layer_load_window);
					}
				  })	
		 });
}
 function editPromotion(id){
		var url=path+"/promotion/to_edit_promotion?promotionId="+id;
	    var index = layer.open({
	        type: 2,
	        title: "编辑广告",
	        scrollbar: false,
	        content: url,
	        area: ['800px', '600px']
	    });
	 
 }
 function addPromotion(){
		var url=path+"/promotion/to_add_promotion";
	    var index = layer.open({
	        type: 2,
	        title: "添加广告",
	        scrollbar: false,
	        content: url,
	        area: ['800px', '600px']
	    });
 }
 function deletePromotion(id){	
   layer.confirm("确定删除？",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		 $.ajax({
				url : path+"/promotion/delete_promotion",
				cache : false,
				type : 'post',
				dataType : 'text',
				data:{'promotionId':id},
				error : function() {
					layer.alert("操作失败！");
		       },
				success : function(data) {
					var resultArr = data.split(",");
			   		if(resultArr[0] == "success"){
						layer.msg("删除成功!",{icon:1,time:1000},function(){
					    	$("#search_form").submit();
						});
			   		}else if(resultArr[0] == "fail"){
			   			layer.alert(resultArr[1]);
			   		}else{
			   			layer.alert(data);
			   		}
				},
				complete: function(XMLHttpRequest, textStatus) {
					layer.close(layer_load_window);
				}
			  })	
	 });
}